using LiJ.Common.Extention;
using System.Collections.Generic;
using System.Xml;

namespace LiJ.Framework.Msg.Mos
{
	/// <inheritdoc />
	/// <summary>
	/// 基础接收消息实体
	/// </summary>
	public class WxBaseRecMsg : WxBaseMsg
	{
		private IDictionary<string, string> _mPropertyDirs;

		/// <summary>
		/// 自定义索引，获取指定字段的值
		/// </summary>
		/// <param name="key"></param>
		public string this[string key]
		{
			get
			{
                _mPropertyDirs.TryGetValue(key, out var text);
				return text ?? string.Empty;
			}
		}

		/// <summary>
		/// 消息实体
		/// </summary>
		public XmlDocument RecMsgXml
		{
			get;
			internal set;
		}

		/// <summary>
		///   消息id
		/// </summary>
		public long MsgId
		{
			get;
			set;
		}

		/// <summary>
		///  把消息的
		/// </summary>
		/// <param name="contentDirs"></param>
		internal virtual void LoadMsgDirs(IDictionary<string, string> contentDirs)
		{
			this._mPropertyDirs = contentDirs;
			base.MsgType = this["MsgType"];
			base.ToUserName = this["ToUserName"];
			base.FromUserName = this["FromUserName"];
			base.CreateTime = this["CreateTime"].ToInt64(0);
			this.MsgId = this["MsgId"].ToInt64(0);
			this.FormatPropertiesFromMsg();
		}

		/// <summary>
		/// 格式化自身属性部分
		/// </summary>
		protected virtual void FormatPropertiesFromMsg()
		{
		}
	}
}
